<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2021/7/6
 * Time: 10:55 下午
 */

namespace app\admin\validator;


use app\lib\BaseValidator;

class AdminMenuValidator extends BaseValidator
{
    protected $rule = [
        'id'             => 'require|isPostInt',
        'title'          => 'require|chsDash|length:2,50',
        'parent_id'      => 'require|number',
        'type'           => 'require|isPostInt',
        'route_name'     => 'require|alphaDash|length:2,50',
        'api_route_name' => 'length:2,100',
        'icon'           => 'alphaDash|length:2,50',
        'cache'          => 'in:0,1',
        'affix'          => 'in:0,1',
        'breadcrumb'     => 'in:0,1',
        'hidden'         => 'in:0,1',
        'sort'           => 'number',
        'remarks'        => 'chsDash|length:1,200'
    ];

    protected $message = [
        'id'             => '参数中缺少id',
        'title.require'  => '菜单名称必填',
        'title.chsDash'  => '菜单名称只能为中文、英文、数字、下划线及减号',
        'title.length'   => '菜单名称长度2-50字',
        'parent_id'      => '父级菜单必须为数字',
        'type'           => '菜单类型只能为正整数',
        'route_name'     => '前端路由名称必填且只能为英文、数字、下划线及减号',
        'api_route_name' => '接口路由名称长度2-100字',
        'icon'           => '图标长度2-50字,只能为英文、数字、下划线及减号',
        'cache'          => '是否缓存只能是0或1',
        'affix'          => '是否固定只能是0或1',
        'breadcrumb'     => '是否面包屑中显示只能是0或1',
        'hidden'         => '是否在菜单中隐藏只能是0或1',
        'sort'           => '排序只能是数字',
        'remarks'        => '备注只能为中文、英文、数字、下划线及减号,长度少于200字'
    ];

    protected $scene = [
        'create' => ['title', 'parent_id', 'type', 'route_name', 'api_route_name', 'icon', 'cache', 'affix', 'breadcrumb', 'hidden', 'sort', 'remarks'],
        'update' => ['id', 'title', 'parent_id', 'type', 'route_name', 'api_route_name', 'icon', 'cache', 'affix', 'breadcrumb', 'hidden', 'sort', 'remarks'],
    ];
}
